home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / turbovis / tvmagic1.zip / MAGICDLG.PAS < prev    next >
Pascal/Delphi Source File  |  1993-06-10  |  9KB  |  268 lines

  1. unit      MagicDlg;
  2.  
  3. { Magic Dialogs by Edwin Groothuis
  4.  
  5.   Gives you the possibility to create a dialog with a hot key.
  6.   If this key is pressed, you get an other text in the dialogbox,
  7.   just like the about-boxes in TP6/TP7/BP7/BC2/BC3 etc.
  8.  
  9.   For usage please see the files DLGTEST.PAS.
  10.  
  11.   There are two different Magic Dialog boxes:
  12.   1. A dialogbox with a static text. This text will be placed there
  13.      when the hotkey is pressed.
  14.      type      PStaticMagicDialog=^TStaticMagicDialog;
  15.                TStaticMagicDialog=object(TMagicDialog)
  16.                                constructor Init(R:TRect;S:String;Key:word);
  17.                                procedure HandleEvent(var E:TEvent);virtual;
  18.                                procedure Draw;virtual;
  19.                                function  GetMagicText(i:word):string;virtual;
  20.                                function  GetNormalText(i:word):string;virtual;
  21.                                function  NumberOfLines:word;virtual;
  22.                                function  FreeLines:word;virtual;
  23.                              end;
  24.      Init: key is the keycode as returned from GetAltChar or GetCtrlChar.
  25.      GetMagicText: returns the MAGIC text on the i-th line (starts from 0)
  26.      GetNormalText: returns the NORMAL text on the i-th line (starts from 0)
  27.                     note: this one can't be longer than the number of
  28.                           freelines!
  29.      NumberOfLines: returns the maximum of the number of lines in the
  30.                     text.
  31.      FreeLines: returns the number of available lines in the dialogbox.
  32.  
  33.  
  34.   2. A dialogbox with a moving text. This text will scroll until the last
  35.      line is reached and restarts from the beginning.
  36.      type      PMovingMagicDialog=^TMovingMagicDialog;
  37.                TMovingMagicDialog=object(TMagicDialog)
  38.                                PrevSec:word;
  39.                                Tick:byte;
  40.                                constructor Init(R:TRect;S:String;Key:word);
  41.                                procedure HandleEvent(var E:TEvent);virtual;
  42.                                procedure Draw;virtual;
  43.                                function  GetMagicText(i:word):string;virtual;
  44.                                function  GetNormalText(i:word):string;virtual;
  45.                                function  NumberOfLines:word;virtual;
  46.                                function  FreeLines:word;virtual;
  47.                              end;
  48.      Init: key is the keycode as returned from GetAltChar or GetCtrlChar.
  49.      GetMagicText: returns the MAGIC text on the i-th line (starts from 0)
  50.      GetNormalText: returns the NORMAL text on the i-th line (starts from 0)
  51.                     note: this one can't be longer than the number of
  52.                           freelines!
  53.      NumberOfLines: returns the maximum of the number of lines in the
  54.                     text.
  55.      FreeLines: returns the number of available lines in the dialogbox.
  56.  
  57.   Note: You always have to override the methods Gettext, NumberOfLines and
  58.         FreeLines. If you don't you'll get runtime error 211 (Call to
  59.         abstract method).
  60.  
  61.   Questions etc. to S89405079@hsepm1.hse.nl (internet)
  62.                  or 2:284/205.1 (fidonet)
  63.  
  64. }
  65. interface
  66.  
  67. uses      Dialogs,Objects,Drivers;
  68.  
  69. type      PMagicDialog=^TMagicDialog;
  70.           TMagicDialog=object(TDialog)
  71.                          Magic:boolean;
  72.                          MagicKey:word;
  73.                          constructor Init(R:TRect;S:String;Key:word);
  74.  
  75. { Note:    }             function  GetMagicText(i:word):string;virtual;
  76. { Override }             function  GetNormalText(i:word):string;virtual;
  77. { these    }             function  NumberOfLines:word;virtual;
  78. { ALWAYS!  }             function  FreeLines:word;virtual;
  79.                        end;
  80. type      PStaticMagicDialog=^TStaticMagicDialog;
  81.           TStaticMagicDialog=object(TMagicDialog)
  82.                                constructor Init(R:TRect;S:String;Key:word);
  83.                                procedure HandleEvent(var E:TEvent);virtual;
  84.                                procedure Draw;virtual;
  85. { Note:    }                   function  GetMagicText(i:word):string;virtual;
  86. { Override }                   function  GetNormalText(i:word):string;virtual;
  87. { these    }                   function  NumberOfLines:word;virtual;
  88. { ALWAYS!  }                   function  FreeLines:word;virtual;
  89.                              end;
  90. type      PMovingMagicDialog=^TMovingMagicDialog;
  91.           TMovingMagicDialog=object(TMagicDialog)
  92.                                PrevSec:word;
  93.                                Tick:byte;
  94.                                constructor Init(R:TRect;S:String;Key:word);
  95.                                procedure HandleEvent(var E:TEvent);virtual;
  96.                                procedure Draw;virtual;
  97. { Note:    }                   function  GetMagicText(i:word):string;virtual;
  98. { Override }                   function  GetNormalText(i:word):string;virtual;
  99. { these    }                   function  NumberOfLines:word;virtual;
  100. { ALWAYS!  }                   function  FreeLines:word;virtual;
  101.                              end;
  102.  
  103. implementation
  104.  
  105. uses      Views,Dos;
  106.  
  107.  
  108. { ---------- MagicDialog ---------- }
  109.  
  110.  
  111. constructor TMagicDialog.Init(R:TRect;S:String;key:word);
  112. begin
  113.   Magic:=false;
  114.   MagicKey:=key;
  115.   Inherited Init(R,S);
  116. end;
  117.  
  118. function  TMagicDialog.GetMagicText(i:word):string;
  119. begin
  120.   Abstract;
  121. end;
  122. function  TMagicDialog.GetNormalText(i:word):string;
  123. begin
  124.   Abstract;
  125. end;
  126. function  TMagicDialog.NumberOfLines:word;
  127. begin
  128.   Abstract;
  129. end;
  130. function  TMagicDialog.FreeLines:word;
  131. begin
  132.   Abstract;
  133. end;
  134.  
  135.  
  136. { ---------- MovingMagicDialog ---------- }
  137.  
  138.  
  139.  
  140. constructor TMovingMagicDialog.Init(R:TRect;S:String;key:word);
  141. begin
  142.   PrevSec:=0;
  143.   Inherited Init(R,S,key);
  144.   MagicKey:=key;
  145. end;
  146.  
  147. procedure TMovingMagicDialog.HandleEvent(var E:TEvent);
  148. var       hour,min,sec,sec100:word;
  149. begin
  150.   if E.What=evKeyDown then
  151.   begin
  152.     if E.KeyCode=MagicKey then
  153.     begin
  154.       magic:=true;
  155.       GetTime(hour,min,sec,sec100);
  156.       PrevSec:=sec;
  157.       repeat GetTime(hour,min,sec,sec100);until sec<>PrevSec;
  158.       PrevSec:=sec;
  159.       Tick:=0;
  160.       Draw;
  161.     end else Inherited HandleEvent(E);
  162.   end else begin
  163.     if E.What=evNothing then
  164.     begin
  165.       if magic then
  166.       begin
  167.         GetTime(hour,min,sec,sec100);
  168.         if sec<>PrevSec then
  169.         begin
  170.           PrevSec:=sec;
  171.           tick:=(tick+1) mod NumberOfLines;
  172.           Draw;
  173.         end;
  174.       end;
  175.     end;
  176.     Inherited HandleEvent(E);
  177.   end;
  178. end;
  179.  
  180. procedure TMovingMagicDialog.Draw;
  181. var       B:TDrawBuffer;
  182.           i:byte;
  183. begin
  184.   Inherited Draw;
  185.   for i:=0 to FreeLines-1 do
  186.   begin
  187.     MoveChar(B,' ',GetColor(1),Size.X-1);
  188.     if magic then
  189.       MoveStr(B,GetMagicText((tick+i) mod NumberOfLines),GetColor(1))
  190.     else
  191.       MoveStr(B,GetNormalText((tick+i) mod NumberOfLines),GetColor(1));
  192.     WriteLine(1,i+1,Size.X-2,1,B);
  193.   end;
  194. end;
  195.  
  196. function  TMovingMagicDialog.GetMagicText(i:word):string;
  197. begin
  198.   Abstract;
  199. end;
  200. function  TMovingMagicDialog.GetNormalText(i:word):string;
  201. begin
  202.   Abstract;
  203. end;
  204. function  TMovingMagicDialog.NumberOfLines:word;
  205. begin
  206.   Abstract;
  207. end;
  208. function  TMovingMagicDialog.FreeLines:word;
  209. begin
  210.   Abstract;
  211. end;
  212.  
  213. { ---------- StaticMagicDialog ---------- }
  214.  
  215. constructor TStaticMagicDialog.Init(R:TRect;S:String;key:word);
  216. begin
  217.   Inherited Init(R,S,key);
  218.   MagicKey:=key;
  219. end;
  220.  
  221. procedure TStaticMagicDialog.HandleEvent(var E:TEvent);
  222. begin
  223.   if E.What=evKeyDown then
  224.   begin
  225.     if E.KeyCode=MagicKey then
  226.     begin
  227.       magic:=true;
  228.       Draw;
  229.     end else Inherited HandleEvent(E);
  230.   end else Inherited HandleEvent(E);
  231. end;
  232.  
  233. procedure TStaticMagicDialog.Draw;
  234. var       B:TDrawBuffer;
  235.           i:byte;
  236. begin
  237.   Inherited Draw;
  238.   for i:=0 to NumberOfLines-1 do
  239.   begin
  240.     MoveChar(B,' ',GetColor(1),Size.X-1);
  241.     if magic then
  242.       MoveStr(B,GetMagicText(i),GetColor(1))
  243.     else
  244.       MoveStr(B,GetNormalText(i),GetColor(1));